import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * Message API返回消息管理
 * @date: 2019-1-9


 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var tenantId = getCurrentOrganizationId();

function message() {
  return isTenantRoleLevel() ? "".concat(tenantId, "/response-messages") : 'response-messages';
}
/**
 * 删除消息
 * @param {Object} params - 参数
 */


export function deleteMessage(_x) {
  return _deleteMessage.apply(this, arguments);
}
/**
 * 查询消息列表
 * @param {Object} params - 查询参数
 */

function _deleteMessage() {
  _deleteMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(message()), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _deleteMessage.apply(this, arguments);
}

export function fetchMessageList(_x2) {
  return _fetchMessageList.apply(this, arguments);
}
/**
 * 创建后端消息
 * @param {Object} params - 参数
 */

function _fetchMessageList() {
  _fetchMessageList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(message()), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchMessageList.apply(this, arguments);
}

export function createMessage(_x3) {
  return _createMessage.apply(this, arguments);
}
/**
 * 修改消息
 * @param {Object} params - 参数
 */

function _createMessage() {
  _createMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(message()), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createMessage.apply(this, arguments);
}

export function updateMessage(_x4) {
  return _updateMessage.apply(this, arguments);
}
/**
 * 查询后端消息明细
 * @param {Object} params - 查询参数
 */

function _updateMessage() {
  _updateMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(message()), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateMessage.apply(this, arguments);
}

export function getMessageDetail(_x5) {
  return _getMessageDetail.apply(this, arguments);
}

function _getMessageDetail() {
  _getMessageDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var messageId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            messageId = params.messageId;
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(message(), "/details/").concat(messageId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _getMessageDetail.apply(this, arguments);
}